import pandas as pd
from datetime import datetime, timedelta

# 读取 Excel 文件
excel_file = "source.xlsx"
df = pd.read_excel(excel_file)

# 定义一个函数来生成开始日期和结束日期
def generate_dates(row):
    year = int(row['年份'])
    month = int(row['月份'])
    start_date = datetime(year, month, 1)
    end_date = start_date + timedelta(days=pd.Period(start_date.strftime('%Y-%m')).days_in_month - 1)
    return start_date, end_date

# 应用函数并创建新的列
df['开始日期'], df['结束日期'] = zip(*df.apply(generate_dates, axis=1))

# 保存到新的 Excel 文件
output_excel_file = "target-gpt35.xlsx"
df.to_excel(output_excel_file, index=False)

print("已生成新的 Excel 文件：", output_excel_file)
